package com.yan.demo.demo2;

/**
 * @author taoge
 * @Date 2024/8/8 11:31
 * @Description
 */
public class MyTask1 implements Runnable {
    private Object obj1;
    private Object obj2;

    public MyTask1(Object obj1, Object obj2) {
        this.obj1 = obj1;
        this.obj2 = obj2;
    }



    @Override
    public void run() {
        synchronized (obj1){
            System.out.println(Thread.currentThread().getName() + "获取了obj1资源");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (obj2){
                System.out.println(Thread.currentThread().getName() + "获取了obj1资源");
            }
        }
    }
}
